import { uuid } from './Common';
import 'katex/dist/katex.min.css';
import katex from 'katex';

// 2D表格元素基类
class Table2DItem{
  constructor(name, row, col){
    this.type = name;

    this.row = row;
    this.col = col;

    this.userName  = '';
    this.uuid      = uuid();
  }

  render(){}
}

class Table2DString extends Table2DItem{
  constructor(str, row, col){
    super('String', row, col);

    this.data = str;
  }

  render(table){
    table.cell(this.row, this.col).innerText = this.data;
  }
}

class Table2DMathString extends Table2DItem{
  constructor(str, row, col){
    super('MathString', row, col);

    this.data = str;
  }

  render(table){
    katex.render(this.data, table.cell(this.row, this.col), {
      throwOnError: false
    });
  }
}

class Table2DHtmlString extends Table2DItem{
  constructor(str, row, col){
    super('HtmlString', row, col);

    this.data = str;
  }

  render(table){
    table.cell(this.row, this.col).innerHTML = this.data;
  }
}
export {Table2DString, Table2DMathString, Table2DHtmlString};